/*
 * Copyright (c) 2016-2020, Chengdu RST technology co., ltd
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-01-06     shijiabao       the first version
 */
#include <COMMON_HEADER/common_header.h>
/**
 *  GPIO 使用情况表：
 *              引脚号       设备号            功能
 *    PE14   78      用于控制485收发，高电平发送，低电平接收
 *    PC2    34      用于DO输出
 *    PD0    48      用于4G CAT1模块电源开关控制，高电平时模块电源关闭，低电平模块电源打开
 *    PD1    49      用于4G CAT1模块开关控制，默认为高电平，此引脚为控制POWERKEY，当为高电平时，POWERKEY为低电平；当为低电平时，POWERKEY为高电平
 * */
#define RS485_PIN_NUM            78
#define DO_PIN_NUM               34
#define CAT1_4G_POWER_PIN_NUM    48
#define CAT1_4G_SWITCH_PIN_NUM   49

void gpio_init(void)
{
    /*引脚为输出模式 */
    rt_pin_mode(RS485_PIN_NUM,PIN_MODE_OUTPUT);
    rt_pin_mode(DO_PIN_NUM,PIN_MODE_OUTPUT);
    rt_pin_mode(CAT1_4G_POWER_PIN_NUM,PIN_MODE_OUTPUT);
    rt_pin_mode(CAT1_4G_SWITCH_PIN_NUM,PIN_MODE_OUTPUT);
    /*默认电平 */
    //recv
    rt_pin_write(RS485_PIN_NUM, PIN_LOW);
    rt_pin_write(DO_PIN_NUM, PIN_LOW);
    //打开供电电源
    //rt_pin_write(CAT1_4G_POWER_PIN_NUM, PIN_LOW);
    rt_pin_write(CAT1_4G_POWER_PIN_NUM, PIN_HIGH);
    //默认不开机
    rt_pin_write(CAT1_4G_SWITCH_PIN_NUM, PIN_LOW);
}

void rs485_pin_on(void)
{
    rt_pin_write(RS485_PIN_NUM, PIN_HIGH);
}

void rs485_pin_down(void)
{
    rt_pin_write(RS485_PIN_NUM, PIN_LOW);
}

void do_pin_on(void)
{
    rt_pin_write(DO_PIN_NUM, PIN_HIGH);
}

void do_pin_down(void)
{
    rt_pin_write(DO_PIN_NUM, PIN_LOW);
}

void cat1_4g_power_pin_on(void)
{
    rt_pin_write(CAT1_4G_POWER_PIN_NUM, PIN_HIGH);
}

void cat1_4g_power_pin_down(void)
{
    rt_pin_write(CAT1_4G_POWER_PIN_NUM, PIN_LOW);
}

void cat1_4g_switch_pin_on(void)
{
    rt_pin_write(CAT1_4G_SWITCH_PIN_NUM, PIN_HIGH);
}

void cat1_4g_switch_pin_down(void)
{
    rt_pin_write(CAT1_4G_SWITCH_PIN_NUM, PIN_LOW);
}

